package com.longxi.tianjintianbao.ui.fragment.energy_read;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.ui.activity.energy_read.EnergyReadListActivity;
import com.longxi.tianjintianbao.ui.base.LazyFragment;
import com.longxi.tianjintianbao.ui.presenter.energy_read.EnergyReadListFgPresenter;
import com.longxi.tianjintianbao.ui.view.energy_read.IEnergyReadListFgView;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

public class EnergyReadListFragment extends LazyFragment<IEnergyReadListFgView, EnergyReadListFgPresenter> implements IEnergyReadListFgView {
    private String state = "-1";

    private int page = 0;

    @Override
    protected int provideContentViewId() {
        return R.layout.include_general_refresh_list;
    }

    @Override
    protected void init(View view) {
        //初始化View
        initView();
        mPresenter.initAdapter();

        //初始化数据
        initData();
    }

    public void initView(){

    }

    @Override
    protected EnergyReadListFgPresenter createPresenter() {
        return new EnergyReadListFgPresenter((EnergyReadListActivity) getActivity());
    }

    private void initData() {
        state = getArguments().getString("state");
        mRefreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {

            @Override
            public void onRefresh(RefreshLayout refreshLayout) {
                mPresenter.getRepairList(page = 0, state);
            }

            @Override
            public void onLoadMore(RefreshLayout refreshLayout) {
                page++;
                mPresenter.getRepairList(page, state);
            }
        });
        mPresenter.getRepairList(page = 0, state);
    }

    public EnergyReadListFragment setArguments(String state) {
        Bundle bundle = new Bundle();
        bundle.putString("state", state);
        setArguments(bundle);
        return this;
    }

    @Override
    public SmartRefreshLayout getRefreshLayout() {
        return mRefreshLayout;
    }

    @Override
    public RecyclerView getRvContent() {
        return mRvContent;
    }

    public void refreshReceiptList() {
        mRefreshLayout.autoRefresh();
    }
}
